<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 
            思路：回溯问题中的组合。比如字符'23'
                a       b      c
             d  e  f| d e f |d e f
            */
            var letterCombinations = function (digits) {
                if (!digits.length) return []
                let res = []
                const map = { 2: 'abc', 3: 'def', 4: 'ghi', 5: 'jkl', 6: 'mno', 7: 'pqrs', 8: 'tuv', 9: 'wxyz' }
                function backTracking(path, start) {
                    //确定终止条件
                    if (path.length == digits.length) {
                        return res.push([...path].join(''))
                    }
                    //确定集合

                    let str = map[digits[start]]

                    for (let i = 0; i < str.length; i++) {
                        path.push(str[i])
                        backTracking(path, start + 1)
                        path.pop()
                    }
                }
                backTracking([], 0)
                return res
            }
            console.log(letterCombinations('23'))
        </script>
    </body>
</html>
